VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CInsulation"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'
'   Copyright (c) 2003-04, Intergraph Corporation. All rights reserved.
'
'   CInsulation.cls
'   Author:          svsmylav
'   Creation Date:  Thursday, Jan 23 2003
'   Description:
' This class module is the place for user to implement graphical part of VBSymbol for this aspect
'   Slide Valve details were taken from PDS Piping Component Data Reference Manual
'   at Page No - D-21 and SN=V33. (PDS Instrument Specialty Symbol
'   SN=I20AZ is same as this symbol)
'
'   This Symbol consist of Physical and Insulation aspects.
'   Physical aspect consist of a Nozzle with Length , Nozzle, branch Cylinder and a Box
'   Insulation aspect consist of a Cylinder for main body ,another cylinder for branch and a Box for
'   Projection at top of Branch
'   The 2 ports for the symbol are fully parametric and can be changed on-the-fly.
'
'   Change History:
'   dd.mmm.yyyy     who     change description
'   -----------         -----        ------------------
'   09.Jul.2003     SymbolTeam(India)       Copyright Information, Header  is added.
'   03.Dec.2004     svsmylav        Defined new input parameter HandwheelAngle.
'  08.SEP.2006     KKC  DI-95670  Replace names with initials in all revision history sheets and symbols
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Option Explicit

Private Const MODULE = "Insulation:" 'Used for error messages
Private m_oCodeListMetadata     As IJDCodeListMetaData

Private Sub Class_Terminate()
    Set m_oCodeListMetadata = Nothing
End Sub

Private Function ReturnMax4(A#, B#, C#, D#) As Double
    Dim MaxValue As Double

    MaxValue = A
    If MaxValue < B Then MaxValue = B
    If MaxValue < C Then MaxValue = C
    If MaxValue < D Then MaxValue = D
    ReturnMax4 = MaxValue
End Function
Public Sub run(ByVal m_OutputColl As Object, ByRef arrayOfInputs(), arrayOfOutputs() As String)
    
    Const METHOD = "run"
    On Error GoTo ErrorLabel
    
    Dim oPartFclt       As PartFacelets.IJDPart
    Dim pipeDiam(1 To 2) As Double
    Dim sptOffset(1 To 2) As Double
    Dim flangeDiam(1 To 2)    As Double
    Dim depth(1 To 2) As Double
    Dim flangeThick(1 To 2) As Double
    
    Dim iOutput     As Double
    Dim ObjBranchInsulation As Object
    Dim ObjBoxInsulation As Object
    Dim ObjBodyInsulation As Object
    
    Dim parFace1toCenter As Double
    Dim parFace2toCenter As Double
    Dim parBranchLength As Double
    Dim parProjectionHeight As Double
    Dim parProjectionLength As Double
    Dim parProjectionWidth As Double
    Dim parInsulationThickness As Double
    Dim InsulationDia1 As Double
    Dim InsulationDia2 As Double
    Dim InsulationDia As Double
    
'   Dynamic Port Input parameters variable declaration
    Dim parNPD As Double
    Dim parEndPreparation As Long
    Dim parScheduleThickness As Long
    Dim parEndStandard As Long
    Dim parPressureRating As Long
    Dim parFlowDirection As DistribFlow
    Dim parNPDUnitType As String

    Dim parPortIndex1 As Long
    Dim parNpd1 As Double
    Dim parEndPreparation1 As Long
    Dim parScheduleThickness1 As Long
    Dim parEndStandard1 As Long
    Dim parPressureRating1 As Long
    Dim parFlowDirection1 As DistribFlow
    Dim parId1 As String
    Dim parNPDUnitType1 As String
    
    Dim parPortIndex2 As Long
    Dim parNpd2 As Double
    Dim parEndPreparation2 As Long
    Dim parScheduleThickness2 As Long
    Dim parEndStandard2 As Long
    Dim parPressureRating2 As Long
    Dim parFlowDirection2 As DistribFlow
    Dim parId2 As String
    Dim parNPDUnitType2 As String
    
    Dim parHandwheelAngle   As Double

' Inputs
    Set oPartFclt = arrayOfInputs(1)
    parFace1toCenter = arrayOfInputs(2) 'A
    parFace2toCenter = arrayOfInputs(3) 'B
    parBranchLength = arrayOfInputs(4)  'J
    parProjectionHeight = arrayOfInputs(5)  'K
    parProjectionLength = arrayOfInputs(6)  'M
    parProjectionWidth = arrayOfInputs(7)   'N
    parInsulationThickness = arrayOfInputs(8)
    parHandwheelAngle = arrayOfInputs(9)
    parNPD = arrayOfInputs(10)
    parEndPreparation = arrayOfInputs(11)
    parScheduleThickness = arrayOfInputs(12)
    parEndStandard = arrayOfInputs(13)
    parPressureRating = arrayOfInputs(14)
    parFlowDirection = arrayOfInputs(15)
    parPortIndex1 = arrayOfInputs(16)
    parNpd1 = arrayOfInputs(17)
    parEndPreparation1 = arrayOfInputs(18)
    parScheduleThickness1 = arrayOfInputs(19)
    parEndStandard1 = arrayOfInputs(20)
    parPressureRating1 = arrayOfInputs(21)
    parFlowDirection1 = arrayOfInputs(22)
    parPortIndex2 = arrayOfInputs(23)
    parNpd2 = arrayOfInputs(24)
    parEndPreparation2 = arrayOfInputs(25)
    parScheduleThickness2 = arrayOfInputs(26)
    parEndStandard2 = arrayOfInputs(27)
    parPressureRating2 = arrayOfInputs(28)
    parFlowDirection2 = arrayOfInputs(29)
    parId1 = arrayOfInputs(30)
    parId2 = arrayOfInputs(31)
    parNPDUnitType = arrayOfInputs(32)
    parNPDUnitType1 = arrayOfInputs(33)
    parNPDUnitType2 = arrayOfInputs(34)
    
    iOutput = 0
    
    If m_oCodeListMetadata Is Nothing Then
        Set m_oCodeListMetadata = m_OutputColl.ResourceManager
    End If
    
    Dim startPoint As AutoMath.DPosition
    Dim endPoint As AutoMath.DPosition
    
    Set startPoint = New AutoMath.DPosition
    Set endPoint = New AutoMath.DPosition
    
  ' Insert your code for output 4(Branch Insulation)
    CreateRetrieveDynamicNozzle 1, parNPD, parNPDUnitType, _
                                            parEndPreparation, parScheduleThickness, parEndStandard, _
                                            parPressureRating, parFlowDirection, parNpd1, _
                                            parNPDUnitType1, parEndPreparation1, parScheduleThickness1, _
                                            parEndStandard1, parPressureRating1, parFlowDirection1, _
                                            parId1, m_OutputColl, m_oCodeListMetadata, _
                                            False, pipeDiam, flangeThick, _
                                            flangeDiam, sptOffset, depth
    startPoint.Set 0, 0, 0
    endPoint.Set 0, parBranchLength - parProjectionHeight, 0
    InsulationDia = pipeDiam(parPortIndex1) + parInsulationThickness * 2
    Set ObjBranchInsulation = PlaceCylinder(m_OutputColl, startPoint, endPoint, InsulationDia, True)

' Set the output
    iOutput = iOutput + 1
    m_OutputColl.AddOutput arrayOfOutputs(iOutput), ObjBranchInsulation
    Set ObjBranchInsulation = Nothing
    
  ' Insert your code for output Projection Box
    Dim lowerpt As AutoMath.DPosition
    Dim upperpt As AutoMath.DPosition
    Set lowerpt = New AutoMath.DPosition
    Set upperpt = New AutoMath.DPosition
    
    lowerpt.Set -parProjectionLength / 2 - parInsulationThickness, _
                        parBranchLength - parProjectionHeight - parInsulationThickness, _
                        parProjectionWidth / 2 + parInsulationThickness
    upperpt.Set parProjectionLength / 2 + parInsulationThickness, _
                        parBranchLength + parInsulationThickness, _
                        -parProjectionWidth / 2 - parInsulationThickness
    Set ObjBoxInsulation = PlaceBox(m_OutputColl, lowerpt, upperpt)
    
' Set the output
    iOutput = iOutput + 1
    m_OutputColl.AddOutput arrayOfOutputs(iOutput), ObjBoxInsulation
    Set ObjBoxInsulation = Nothing
    Set lowerpt = Nothing
    Set upperpt = Nothing
 
 ' Insert your code for output 3(Body Insulation)
'   Maximum of pipeDiam, flangeDiam of ports 1 and 2 is  used to compute insulation diameter
    InsulationDia = ReturnMax4(pipeDiam(parPortIndex1), flangeDiam(parPortIndex1), _
                            pipeDiam(parPortIndex2), flangeDiam(parPortIndex2)) + _
                            2 * parInsulationThickness
    startPoint.Set -parFace1toCenter, 0, 0
    endPoint.Set parFace2toCenter, 0, 0
    Set ObjBodyInsulation = PlaceCylinder(m_OutputColl, startPoint, endPoint, InsulationDia, True)
    
' Set the output
    iOutput = iOutput + 1
    m_OutputColl.AddOutput arrayOfOutputs(iOutput), ObjBodyInsulation
    Set ObjBodyInsulation = Nothing
    Set startPoint = Nothing
    Set endPoint = Nothing
    
    Exit Sub
    
ErrorLabel:
    ReportUnanticipatedError MODULE, METHOD
    Resume Next
    
End Sub
